<?php
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

/*****************************
 *Tramite - Departamento
 *****************************/

$strSql  = "SELECT id4, s.des as tramite ";
$strSql .= "FROM solotb_nivel4 s ";
$strSql .= "order by tramite";
SoloFun_ExecSql ($strSql,$arrData1);
//echo $strSql;
if ($_REQUEST["CmbTramite"] != "") {
    $strid1 = $_REQUEST["CmbTramite"];
}else {
    $strid1 = $arrData1[0][0];
}
//echo $strid1."<br>";
foreach($arrData1 as $tramite) {
    if($strid1 == $tramite[1]) {
        $strid2 = $tramite[3];
        break;
    }
}
//echo $strid2;
/*****************************
 * DPTO. 1
 *****************************/
$strSql  = "select id2, des from solotb_nivel2";
$strSql .= " order by des";
SoloFun_ExecSql ($strSql,$arrData2);

/******************************
 * DPTO. 2
 ******************************/
$arrData3 = $arrData2;

/*****************************
 *  DPTO. 3
 *****************************/
$arrData4 = $arrData3;


/*****************************
 * DPTO. 4
 *****************************/
$arrData5 = $arrData4;

/*****************************
 * DPTO. 5
 *****************************/
$arrData6 = $arrData5;

$strSql = "select f.cod_tramite, a.des, f.cod_dep1, b.des, f.cod_dep2, c.des, f.cod_dep3, d.des, f.cod_dep4, e.des, f.cod_dep5, g.des
    from tb_flujo f
    left join solotb_nivel4 a on f.cod_tramite = a.id4
    left join solotb_nivel2 b on f.cod_dep1 = b.id2
    left join solotb_nivel2 c on f.cod_dep2 = c.id2
    left join solotb_nivel2 d on f.cod_dep3 = d.id2
    left join solotb_nivel2 e on f.cod_dep4 = e.id2
    left join solotb_nivel2 g on f.cod_dep5 = g.id2";
SoloFun_ExecSql($strSql, $arrFlujo);
?>
<html>
    <head>
        <title>Administrar Procesos</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
        <SCRIPT type="text/JavaScript" src="Includes/Solofun_generales.js"></SCRIPT></head>

    <body topmargin=0 leftmargin=0>
        <!-- Include File="includes/trn_header.asp" -->
        <p align="center" class="SoloStyle_TituloPaginas">Administrar Procesos</p>
        <form name="frmIngreso" action="trn_GrabaAdministrarProcesos.php" method="POST">
            <table border="0" width="50%" align="center">
                <tr>
                    <td width="30%" class="SoloStyle_Etiqueta"><strong>Tr&aacute;mite</strong></td>
                    <td width="70%">
                        <?php
                        /*****************************
 * TRAMITE
 *****************************/
                        ?>
                        <select name="CmbTramite" id="CmbTramite" class="SoloStyle_Texto" onChange="submitpage('solotrn_AdministrarProcesos.php','1');" style="width:185px">
                            <?php
                            for ($i=0;$i < count($arrData1);$i++) {
                                if(!empty($arrData1[$i][1])) {
                                    $ind=$arrData1[$i][0];
                                    $jnd=$_REQUEST["CmbTramite"];
                                    if ($jnd==$ind) {
                                        echo "<option value='" . $arrData1[$i][0] . "' SELECTED >" . $arrData1[$i][1] . "</option>";

                                    } else {
                                        echo "<option value='" . $arrData1[$i][0] . "'>" . $arrData1[$i][1] . "</option>";
                                    }
                                }
                            }
                            ?>
                        </select> </td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Departamento 1</b></td>
                    <td class="SoloStyle_Texto">
                        <?php
                        /*****************************
 *  DPTO. 1
 *****************************/
                        ?>
                        <?php
                        /*for ($i=0 ;$i < count($arrData2);$i++) {
                            $ind2=$arrData2[$i][0];
                            $jnd2 = $strid2;
                            if ($jnd2==$ind2) {
                                echo $arrData2[$i][1];
                                echo "<input type=\"hidden\" name=\"CmbDpto1\" value='" . $arrData2[$i][0] . "'/>";
                            }
                        }*/

                        ?>
                        <select name="CmbDpto1" id="select" class="SoloStyle_Texto" style="width:185px">
                            <?php
                            if (!$bEOF2) {
                                echo "<option value=''>Seleccione Departamento...</option>";
                                for ($i=0 ;$i < count($arrData2);$i++) {
                                    $ind2=$arrData2[$i][0];
                                    //$jnd2=$_REQUEST["CmbDpto1"];
                                    $jnd2 = $strid2;
                                    if ($jnd2==$ind2) {
                                        echo "<option value='" . $arrData2[$i][0] . "' SELECTED >" . $arrData2[$i][1] . "</option>";
                                    }else {
                                        echo "<option value='" . $arrData2[$i][0] . "'>" . $arrData2[$i][1] . "</option>";
                                    }
                                }
                            }else {
                                echo "<option value='0'>" . "NO HAY DATOS" . "</option>";
                            }
                            ?>
                        </select>

                    </td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Departamento 2</b></td>
                    <td>
                        <?php
                        /*****************************
 * DPTO. 2
 *****************************/
                        ?>
                        <select name="CmbDpto2" id="select3" class="SoloStyle_Texto" style="width:185px">
                            <?php
                            if (!$bEOF3) {
                                echo "<option value=''>Seleccione Departamento...</option>";
                                for ($i=0;$i < count($arrData3);$i++) {
                                    $ind2=$arrData3[$i][0];
                                    $jnd2=$_REQUEST["CmbDpto2"];
                                    If ($jnd2==$ind2) {
                                        echo "<option value='" . $arrData3[$i][0] . "' SELECTED >" . $arrData3[$i][1] . "</option>";
                                    }else {
                                        echo "<option value='" . $arrData3[$i][0] . "'>" . $arrData3[$i][1] . "</option>";
                                    }
                                }
                            }else {
                                echo "<option value='0'>" . "NO HAY DATOS" . "</option>";
                            }
                            ?>
                        </select></td>
                </tr>
                <!-- -->

                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Departamento 3</b></td>
                    <td>
                        <?php
                        /******************************
 * DPTO. 3
 *****************************/
                        ?>
                        <select name="CmbDpto3" class="SoloStyle_Texto" style="width:185px">
                            <?php
                            if (!$bEOF4) {
                                echo "<option value=''>Seleccione Departamento...</option>";
                                for ($i=0;$i < count($arrData4);$i++) {
                                    $ind2=$arrData4[$i][0];
                                    $jnd2=$_REQUEST["CmbDpto3"];
                                    if (jnd2==ind2) {
                                        echo "<option value='" . $arrData4[$i][0] . "' SELECTED >" . $arrData4[$i][1] . "</option>";
                                    }else {
                                        echo "<option value='" . $arrData4[$i][0] . "'>" . $arrData4[$i][1] . "</option>";
                                    }
                                }
                            }else {
                                echo "<option value='0'>" . "NO HAY DATOS" . "</option>";
                            }
                            ?>
                        </select></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Departamento 4</b></td>
                    <td>
                        <?php
                        /******************************
 * DPTO. 4
 *****************************/
                        ?>
                        <select name="CmbDpto4" class="SoloStyle_Texto" style="width:185px">
                            <?php
                            if (!$bEOF4) {
                                echo "<option value=''>Seleccione Departamento...</option>";
                                for ($i=0;$i < count($arrData5);$i++) {
                                    $ind2=$arrData5[$i][0];
                                    $jnd2=$_REQUEST["CmbDpto4"];
                                    if (jnd2==ind2) {
                                        echo "<option value='" . $arrData5[$i][0] . "' SELECTED >" . $arrData5[$i][1] . "</option>";
                                    }else {
                                        echo "<option value='" . $arrData5[$i][0] . "'>" . $arrData5[$i][1] . "</option>";
                                    }
                                }
                            }else {
                                echo "<option value='0'>" . "NO HAY DATOS" . "</option>";
                            }
                            ?>
                        </select></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Departamento 5</b></td>
                    <td>
                        <?php
                        /******************************
 * DPTO. 5
 *****************************/
                        ?>
                        <select name="CmbDpto5" class="SoloStyle_Texto" style="width:185px">
                            <?php
                            if (!$bEOF4) {
                                echo "<option value=''>Seleccione Departamento...</option>";
                                for ($i=0;$i < count($arrData6);$i++) {
                                    $ind2=$arrData6[$i][0];
                                    $jnd2=$_REQUEST["CmbDpto5"];
                                    if (jnd2==ind2) {
                                        echo "<option value='" . $arrData6[$i][0] . "' SELECTED >" . $arrData6[$i][1] . "</option>";
                                    }else {
                                        echo "<option value='" . $arrData6[$i][0] . "'>" . $arrData6[$i][1] . "</option>";
                                    }
                                }
                            }else {
                                echo "<option value='0'>" . "NO HAY DATOS" . "</option>";
                            }
                            ?>
                        </select></td>
                </tr>
            </table>
            <br><center>
                <input type="button" name="CmdGrabar" value="Grabar" class="SoloStyle_Boton" onClick="SoloFun_Submit(document.frmIngreso)"></center>
            <input type="hidden" name="opc" value="G">
        </form>
        <table width="75%" border="0" align="center" class="SoloStyle_Grid">
            <tr class="SoloStyle_Etiqueta">
                <td width="15%">Tr&aacute;mite</td>
                <td width="15%">Departamento 1</td>
                <td width="15%">Departamento 2</td>
                <td width="15%">Departamento 3</td>
                <td width="15%">Departamento 4</td>
                <td width="15%">Departamento 5</td>
                <td width="10%">Acci&oacute;n</td>
            </tr>
            <?php
            if(count($arrFlujo) > 0) {
                for ($i=0;$i < count($arrFlujo);$i++) {?>

            <tr>
                <td><?php echo $arrFlujo[$i][1];?></td>
                <td><?php echo $arrFlujo[$i][3];?></td>
                <td><?php echo $arrFlujo[$i][5];?></td>
                <td><?php echo $arrFlujo[$i][7];?></td>
                <td><?php echo $arrFlujo[$i][9];?></td>
                <td><?php echo $arrFlujo[$i][11];?></td>
                <td><a href="trn_GrabaAdministrarProcesos.php?id1=<?php echo $arrFlujo[$i][0];?>&id2=<?php echo $arrFlujo[$i][1];?>&id3=<?php echo $arrFlujo[$i][2];?>&id4=<?php echo $arrFlujo[$i][3];?>&opc=M">
                        <img src='iconos/soloico_modificar.gif' alt='Modificar' width="23" height="19" border='0' style='cursor:hand' ></a>&nbsp;
                    <a href="#" onClick="Comprobar('trn_GrabaAdministrarProcesos.php?id1=<?php echo $arrFlujo[$i][0];?>&id2=<?php echo  $arrFlujo[$i][1];?>&id3=<?php echo $arrFlujo[$i][2];?>&id4=<?php echo $arrFlujo[$i][3];?>&opc=E')">
                        <img src='iconos/soloico_eliminar.gif' alt='Borrar Campos' width="23" height="19" border='0' style='cursor:hand'></a>&nbsp;
                </td>
            </tr>
                    <?php }
            }else {
                ?>
            <tr>
                <td colspan="7" style="text-align: center">No se encontraron registros para mostrar</td>
            </tr>
                <?php
            }
            ?>
        </table>
    </body>
</html>
<!--#include file="Includes/soloFun_ShowMessages.php"-->
<SCRIPT type="text/JavaScript" src="PHPMailer/fun_generales.js"></SCRIPT>
<script type="text/JavaScript">
    function Comprobar(pagina){
        var conf = confirm("Confirma Eliminar");
        if (conf)
            window.location.href = pagina;
    }

</script>